package com.bayihouse.service.impl;

import com.alibaba.excel.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bayihouse.mapper.TempermitMapper;
import com.bayihouse.model.entity.Tempermit;
import com.bayihouse.model.request.tempermit.TempermitQueryRequest;
import com.bayihouse.model.vo.TempermitVO;
import com.bayihouse.service.TempermitService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author Administrator
* @description 针对表【tempermit】的数据库操作Service实现
* @createDate 2025-04-23 02:22:33
*/
@Service
public class TempermitServiceImpl extends ServiceImpl<TempermitMapper, Tempermit>
    implements TempermitService {

    @Override
    public TempermitVO getTempermitVO(Tempermit tempermit) {
        if (tempermit == null) {
            return null;
        }
        return TempermitVO.objToVo(tempermit);
    }

    @Override
    public Wrapper<Tempermit> getQueryWrapper(TempermitQueryRequest tempermitQueryRequest) {
        Long id = tempermitQueryRequest.getId();
        String comuntyname = tempermitQueryRequest.getComuntyname();
        String name = tempermitQueryRequest.getName();
        Integer category = tempermitQueryRequest.getCategory();
        String telephone = tempermitQueryRequest.getTelephone();
        String address = tempermitQueryRequest.getAddress();
        Date createtime = tempermitQueryRequest.getCreatetime();
        Date dealtime = tempermitQueryRequest.getDealtime();
        Integer status = tempermitQueryRequest.getStatus();
        String detail = tempermitQueryRequest.getDetail();
        long current = tempermitQueryRequest.getCurrent();
        long pageSize = tempermitQueryRequest.getPageSize();
        String sortField = tempermitQueryRequest.getSortField();
        String sortOrder = tempermitQueryRequest.getSortOrder();
        QueryWrapper<Tempermit> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(id != null, "id", id);
        queryWrapper.like(StringUtils.isNotBlank(name), "name", name);
        queryWrapper.like(StringUtils.isNotBlank(address), "address", address);
        queryWrapper.like(StringUtils.isNotBlank(detail), "detail", detail);
        queryWrapper.eq(category != null, "category", category);
        queryWrapper.eq(status != null, "status", status);
        queryWrapper.eq(StringUtils.isNotBlank(comuntyname), "comuntyname", comuntyname);
        queryWrapper.eq(StringUtils.isNotBlank(telephone), "telephone", telephone);
        return queryWrapper;
    }

    @Override
    public List<TempermitVO> getTempermitVOList(List<Tempermit> records) {
        if (CollectionUtils.isEmpty(records)) {
            return new ArrayList<>();
        }
        return records.stream().map(this::getTempermitVO).collect(Collectors.toList());
    }


}




